package day10.part1;

/**
 * @Author juzipi
 * @Date 2021/6/24 15:10
 * @Info
 */
public class Account {

    private int id;
    private double balance;
    private double annualInterestRate;//年利率

    public Account() {
    }

    public Account(int id, double balance) {
        this.id = id;
        this.balance = balance;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    //取钱
    public void withdraw(double amount){
        if (balance < amount){
            System.out.println("余额不足，取款失败");
            return;
        }
        balance -= amount;
        System.out.println("取出："+amount);
    }

    public double CalculateInterestRate(double balance){
        if (balance <= 2000 && balance >= 0){
            return 0.0123;
        }
        if (balance >= 2000 && balance<=10000){
            return 0.0223;
        }else {
            return 0.333;
        }

    }

    //存钱
    public void deposit(double amount){
        if (amount > 0){
            balance += amount;
            System.out.println("存:"+amount);
        }
    }

}

class CustomerTest{
    public static void main(String[] args) {
        Customer customer = new Customer("Zhang","san");
        Account account = new Account(1000,2000);
        customer.setAccount(account);
        customer.getAccount().deposit(1000);
        customer.getAccount().withdraw(300);
        account.setAnnualInterestRate(account.CalculateInterestRate(account.getBalance()));
        System.out.println("id:"+account.getId()+" 余额 "+account.getBalance()+" 利率 "+account.getAnnualInterestRate());
    }
}

class Customer{

    private String firstName;

    private String lastName;

    private Account account;

    public Customer(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }
}
